package com.wang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.mapper.TbTopicAllMapper;
import com.wang.mapper.TbTopicSimplyMapper;
import com.wang.mapper.TbUserAnswerMapper;
import com.wang.pojo.TbTopic;
import com.wang.pojo.TbTopicAll;
import com.wang.pojo.TbTopicSimply;
import com.wang.pojo.TbUserAnswer;
import com.wang.service.TbTopicService;
import com.wang.mapper.TbTopicMapper;
import com.wang.utills.JwtUtil;
import com.wang.utills.R;
import com.wang.utills.Result;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yaml.snakeyaml.events.Event;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题目表
 */
@Service
@Transactional
public class TbTopicServiceImpl extends ServiceImpl<TbTopicMapper, TbTopic>
    implements TbTopicService{

    @Resource
    private  TbTopicMapper tbTopicMapper;

    @Resource
    private TbTopicSimplyMapper tbTopicSimplyMapper;   //简单问卷

    @Resource
    private TbTopicAllMapper tbTopicAllMapper;   //综合

    @Resource
    private TbUserAnswerMapper tbUserAnswerMapper;  //答卷


    @Override
    public R addnewtopic(TbTopic tbTopic) {
        tbTopicMapper.insert(tbTopic);
        return new R(200, "true", null);
    }

    @Override
    public R delbuytid(Integer tid) {

        this.tbTopicMapper.deleteById(tid);
        return null;
    }

    @Override
    public R findtopicsimplyall() {


        return null;
    }

    @Override
    public R upbuytid(TbTopic tbTopic) {
        this.tbTopicMapper.updateById(tbTopic);
        return null;
    }

    @Override
    public R addtopicsimply(TbTopicSimply tbTopicSimply) {

        this.tbTopicSimplyMapper.insert(tbTopicSimply);
        return null;
    }

    @Override
    public R deltopicsimply(Integer qid) {
        this.tbTopicSimplyMapper.deleteById(qid);
        return R.SUCCESS(200, "奈斯");
    }

    @Override
    public R findTopicAll() {
        List<TbTopicAll> allList = tbTopicAllMapper.selectList(new QueryWrapper<>());
        return R.SUCCESS(200, "nainis", allList);
    }

    @Override
    public R addtopicanswer(TbUserAnswer tbUserAnswer) {
        tbUserAnswerMapper.insert(tbUserAnswer);
        return R.SUCCESS(200, "奈斯");
    }

    @Resource
    private JwtUtil jwtUtil;

    @Override
    public R addreport(String toukes) {
        String id = jwtUtil.parseJWT(toukes).getId();
        Integer uid=Integer.valueOf(id);

        return null;
    }
}




